package api

import (
	"github.com/gogf/gf/errors/gerror"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gvalid"
	"shrimp-blog-server/app/model"
	"shrimp-blog-server/utils"
)

func (*apiLabel) Get(request *ghttp.Request) {
	labelService.GetLabel(request, getQueryParamID(request)...)
}

func (*apiLabel) Post(request *ghttp.Request) {
	var labels []model.LabelRequest

	_ = request.Parse(&labels)
	if e := gvalid.CheckStructWithData(request.Context(), model.LabelRequest{}, labels, nil); e != nil {
		g.Log().Info(gerror.Current(e))
		utils.Response.ErrorResponseExit(request, gerror.Current(e).Error())
	}
	labelService.AddLabel(request, labels...)

}

func (*apiLabel) Put(request *ghttp.Request) {
	var labels []model.LabelRequest
	_ = request.Parse(&labels)
	if e := gvalid.CheckStructWithData(request.Context(), model.LabelRequest{}, labels, nil); e != nil {
		g.Log().Info(gerror.Current(e))
		utils.Response.ErrorResponseExit(request, gerror.Current(e).Error())
	}
	labelService.UpdateLabel(request, labels...)
}

func (*apiLabel) Delete(request *ghttp.Request) {
	labelService.DeleteLabel(request, getQueryParamID(request)...)
}

func (*apiLabel) GetListPage(request *ghttp.Request) {
	labelService.GetLabelPage(request, getPage(request))
}
